#include "connection.hpp"

int main()
{
    // 1.实例化异步工作线程对象
    zhong::AsyncWorker::ptr worker = std::make_shared<zhong::AsyncWorker>();
    // 2.实例化连接对象
    zhong::Connection::ptr connection = std::make_shared<zhong::Connection>("127.0.0.1", 8888, worker);
    // 3.通过链接创建并获取信道
    zhong::Channel::ptr channel = connection->openChannel();
    google::protobuf::Map<std::string, std::string> args;
    // 进行业务前需要指定虚拟机
    channel->selectVirtualHost("defaultHost");

    channel->declareExchange("exchange1", zhong::ExchangeType::TOPIC, true, false, args);

    channel->declareQueue("queue1", true, false, false, args);
    channel->declareQueue("queue2", true, false, false, args);
    //      3.添加绑定信息
    channel->bind("exchange1", "queue1", "new.study.#");
    channel->bind("exchange1", "queue2", "news.music.#");
    std::this_thread::sleep_for(std::chrono::seconds(3));
    //      1.测试FANOUT
    // for (size_t i = 0; i < 10; i++)
    // {
    //     channel->basicPublish("exchange_a", nullptr, "Hello-world-" + std::to_string(i));
    //     std::this_thread::sleep_for(std::chrono::seconds(1));
    // }

    //      2.测试DIRICT
    // for (size_t i = 0; i < 10; i++)
    // {
    //     zhong::BasicProperties bp;
    //     bp.set_id(UUIDer::uuid());
    //     bp.set_delivery_mode(zhong::DeliveryMode::DURABLE);
    //     bp.set_routing_key("queue_a");
    //     channel->basicPublish("exchange_a", &bp, "Hello-world-" + std::to_string(i));
    //     std::this_thread::sleep_for(std::chrono::seconds(1));
    // }

    //      3.测试TOPIC
    for (size_t i = 0; i < 10; i++)
    {
        zhong::BasicProperties bp;
        bp.set_id(UUIDer::uuid());
        bp.set_delivery_mode(zhong::DeliveryMode::DURABLE);
        bp.set_routing_key("news.music.pop");
        channel->basicPublish("exchange1", &bp, "Hello-world-" + std::to_string(i));
        std::this_thread::sleep_for(std::chrono::seconds(1));
    }
    zhong::BasicProperties bp1;
    bp1.set_id(UUIDer::uuid());
    bp1.set_delivery_mode(zhong::DeliveryMode::DURABLE);
    bp1.set_routing_key("news.music.light");
    channel->basicPublish("exchange1", &bp1, "Hello-music");

    zhong::BasicProperties bp2;
    bp2.set_id(UUIDer::uuid());
    bp2.set_delivery_mode(zhong::DeliveryMode::DURABLE);
    bp2.set_routing_key("news.study.math");
    channel->basicPublish("exchange1", &bp2, "测试Queue1-Hellostudy");
    
    while (1)
    {
        std::this_thread::sleep_for(std::chrono::seconds(3));
    }
}